﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="list.aspx.cs" Inherits="DeansWsccProject.list" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <h1>List of eBooks</h1>
    <h3>Filter list of eBooks by Tag</h3>
    <asp:HyperLink ID="hlShowAllEBooks" runat="server" NavigateUrl="/list.aspx">All</asp:HyperLink>
    <asp:Repeater ID="eBooksTagsListRepeater" runat="server" DataSourceID="eBookTagsListSqlDataSource">
        <ItemTemplate>
            <a href='/list.aspx?tag=<%# Eval("tag") %>'><%# Eval("tag") %></a>
        </ItemTemplate>
    </asp:Repeater>
    <asp:SqlDataSource ID="eBookTagsListSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:DeansWsccProjectConnectionString %>" ProviderName="<%$ ConnectionStrings:DeansWsccProjectConnectionString.ProviderName %>" SelectCommand="SELECT [tag] FROM [tags] ORDER BY [tag]"></asp:SqlDataSource>
    <br />
    <asp:GridView ID="eBookListGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" AllowSorting="True">
        <Columns>
            <asp:TemplateField HeaderText="Title of eBook" SortExpression="eBookTitle" ItemStyle-HorizontalAlign="Center">
                <ItemTemplate>
                    <a href="/details.aspx?ID=<%# Eval("ID") %>"><img class="eBookImage" src="/<%# Eval("eBookImage") %>" alt="<%# Eval("eBookTitle") %> image not available" /></a>
                    <br />
                    <a class='eBookTitle' href='/details.aspx?ID=<%# Eval("ID") %>'><%# Eval("eBookTitle") %></a>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Rating" SortExpression="eBookRating">
                <ItemTemplate>
                    <%# DeansWsccProject.App_Code.functions.getRating(Convert.ToString(Eval("eBookRating"))) %>

                    <!-- Show no. reviews link only if eBook has been rated at least once -->
                    <span runat='server' Visible='<%# Convert.ToString(Eval("eBookRating")) != "" %>'>
                        <br />
                        <a href='/details.aspx?ID=<%# Eval("ID") %>#recent-reviews'>(<%# DeansWsccProject.App_Code.functions.getNoReviews(Convert.ToString(Eval("ID"))) %> Reviews)</a>
                    </span>

                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Released" SortExpression="eBookReleaseDate">
                <ItemTemplate>
                    <%# Convert.ToString(Eval("eBookReleaseDate")).Remove(10, 9) %>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="details.aspx?ID={0}" HeaderText="More Details" Text="View More" >
                <ControlStyle CssClass="eBookViewDetails" />
            </asp:HyperLinkField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DeansWsccProjectConnectionString %>" ProviderName="<%$ ConnectionStrings:DeansWsccProjectConnectionString.ProviderName %>" CancelSelectOnNullParameter="False">
        <SelectParameters>
            <asp:QueryStringParameter Name="tag" QueryStringField="tag" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>
